<?php

class Admin_Form_News extends Zend_Form {

	const TITLE = 'Tiêu đề';
	const INTRODUCTION = 'Giới thiệu';
	const CONTENT = 'Nội dung';
	const IMAGE = 'Ảnh đại diện';
	const TOTAL_VIEW = 'Số lượt xem';
	const SAVE = 'Save';
	const RESET = 'Reset';
	const IMAGE_EXTENSION = 'jpg,jpeg,png,gif';
	const IMAGE_DESCRIPTION = 'Dung lượng ảnh <= 2MB. Định dạng ảnh jpeg, jpg, gif, png.';

	private function createIdElement() {
		$id = new Zend_Form_Element_Hidden('id');
		$id->addFilter('Int');
		return $id;
	}

	private function createTitleElement() {
		$title = new Zend_Form_Element_Text('tieu_de');
		$title->setLabel(self::TITLE)
			  ->setRequired(true)
			  ->addFilter('StringTrim')
			  ->addFilter('StripTags')
			  ->addValidator('NotEmpty', true)
			  ->setAttribs(array("maxlength" => "100"));
		return $title;
	}

	private function createIntroductionElement() {
		$introduction = new Zend_Form_Element_Textarea('gioi_thieu');
		$introduction->setLabel(self::INTRODUCTION)
				   	 ->setRequired(true)
				   	 ->addFilter('StringTrim')
				   	 ->addFilter('StripTags')
				   	 ->addValidator('NotEmpty', true)
				   	 ->setAttribs(array("style" => "width: 700px; height: 100px;", "maxlength" => "200"));
		return $introduction;
	}

	private function createContentElement() {
		$content = new Zend_Form_Element_Textarea('noi_dung');
		$content->setLabel(self::CONTENT)
				->setRequired(true)
				->addFilter('StringTrim')
				->addValidator('NotEmpty', true);
		return $content;
	}

	private function createFileElement() {
		$image = new Zend_Form_Element_File('hinh_anh');
        $image->setLabel(self::IMAGE)
        	  ->setDescription(self::IMAGE_DESCRIPTION)
        	  ->setAttribs(array('style' => 'font-size: 18px', 'size' => '30'))
        	  ->addValidator('Extension', true, self::IMAGE_EXTENSION)
			  ->addValidator(new Zend_Validate_File_FilesSize(array('max' => (2 * 1024 * 1024))));
		return $image;
	}

	private function createTotalViewElement() {
		$totalView = new Zend_Form_Element_Text('luot_xem');
		$totalView->setLabel(self::TOTAL_VIEW)
			  	  ->setRequired(true)
			  	  ->addFilter('StringTrim')
			  	  ->addValidator('NotEmpty', true)
			  	  ->addValidator('Digits')
			  	  ->setAttribs(array("maxlength" => "9"));
		return $totalView;
	}

	private function createSubmitElement() {
		$submit = new Zend_Form_Element_Submit('submit');
        $submit->setAttrib('id', 'submitbutton')
        	   ->removeDecorator('DtDdWrapper')
        	   ->setLabel(self::SAVE)
        	   ->setAttrib("class", "btn btn-large btn-primary ");
       	return $submit;
	}

	private function createResetElement() {
		$reset = new Zend_Form_Element_Reset('reset'); 
		$reset->setAttrib('id', 'resetbutton')
			  ->removeDecorator('DtDdWrapper')
			  ->setLabel(self::RESET)
			  ->setAttrib("class", "btn btn-large");
		return $reset;	  
	}

    public function init() {
        $this->setName('news');
        $this->setMethod('post');
        $this->setAttrib('enctype', 'multipart/form-data');

		$id = $this->createIdElement();
		$title = $this->createTitleElement();
		$introduction = $this->createIntroductionElement();
		$content = $this->createContentElement();
		$totalView = $this->createTotalViewElement();
		$image = $this->createFileElement();		
		$submit = $this->createSubmitElement();
		$reset = $this->createResetElement();

        $this->addElements(array($id, $title, $totalView, $image, $introduction, $content, $submit, $reset));

		$this->addDisplayGroup(array('submit', 'reset'), 'buttons');
		$dg = $this->getDisplayGroup('buttons');
		$dg->removeDecorator('Fieldset');
		$dg->removeDecorator('HtmlTag');      
    }

}
?>